/*
 * fuseLayer.h
 *
 *  Created on: 17/09/2011
 *      Author: utn_so
 */

#ifndef FUSELAYER_H_
#define FUSELAYER_H_

#include "structsFAT.h"

typedef struct Nodo_FILE_INFO {
	FILE_INFO aFile;
	struct Nodo_FILE_INFO *nxt;
} Nodo_FILE_INFO;

typedef struct List_FILE_INFO {
	Nodo_FILE_INFO *Head;
	Nodo_FILE_INFO *Tail;
	CLUSTER firstCluster;
} List_FILE_INFO;

int getEntrysFromPath(const char * path, List_FILE_INFO *Listdir);
int SearchListFiles(List_FILE_INFO * Listdir, const char * aFileName);
int setFileInfoByFileName(List_FILE_INFO * Listdir, const char * aFileName, FILE_INFO * aFile);
void List_FILE_INFO_Init(List_FILE_INFO * Listdir);
void List_FILE_INFO_Destroy(List_FILE_INFO * Listdir);
int readBootSector();
int loadFileAllocationTable();
void FreeFileAllocationTable();
int writeDataToFile(const char * path, const char * buf, int32_t size, CLUSTER * newFirstCluster, uint32_t offset, FILE_INFO * aFileInfo);
int readDataFromChainCluster(CLUSTER firstCluster, char * bufferOut, int32_t size, const char * path, uint32_t offset);
int RemoveEntryFromDirectory(List_FILE_INFO * aListDirectory, FILE_INFO aFile);
int AddEntryToDirectory(List_FILE_INFO * aListDirectory, FILE_INFO aFile, int isDirectory /*boolean*/, int create /*boolean*/);
int freeChainCluster(CLUSTER firstCluster);
int freeChainCluster_noUp(CLUSTER firstCluster);
int truncateChainCluster(FILE_INFO * aFile, int32_t size);
int UpdateClusterFile(CLUSTER ClusterToUpdate, FILE_INFO fileInfo);
CLUSTER getFreeCluster();
void assignCreateDate(FILE_INFO * aFile);
void logChainClusters(CLUSTER firstCluster, char ** strlog);

#endif /* FUSELAYER_H_ */
